#ifndef DATAMONITOR_H
#define DATAMONITOR_H

#include <QWidget>
#include <QTreeWidget>
#include "sqlitemanage.h"
#include "serialportmanage.h"
#include <QMessageBox>
#include "monitorpointwidget.h"
#include "serialconfigdialog.h"
#include "historydatawidget.h"
#include "logclass.h"

QT_BEGIN_NAMESPACE
namespace Ui { class DataMonitor; }
QT_END_NAMESPACE


class DataMonitor : public QWidget
{
    Q_OBJECT

public:
    DataMonitor(QWidget *parent = nullptr);
    ~DataMonitor();
    void setUserName(QString &name);
    QPushButton* createToolButton(const QIcon &icon, const QString &text);
    void initStyles();

signals:
    void sendDataPoint(int &device_id,const DataPoint &data);

private slots:
    void onTreeItemSelected();
    void addMonitorPoint();
    void removeMonitorPoint(MonitorPointWidget *widget);
    //void rearrangeMonitorPoints();
    //bool isMonitorPointExists(const QString &location);

    void addSerialConfig();
    void editSerialConfig();
    void deleteSerialConfig();
    void ensureWidgetVisible(QWidget *widget);
    void adjustScrollAreaSize();
    void rearrangeGridLayout();
    void loadSerialConfigs();

private:
    Ui::DataMonitor *ui;
    SerialPortManage *m_pSerialManage;
    SqliteManage *m_pSqliteManage;
    QPushButton *m_addConfigButton;
    QPushButton *m_editConfigButton;
    QPushButton *m_deleteConfigButton;
    QTreeWidget *m_treeWidget;
    QPushButton *m_addButton;
    QScrollArea *m_scrollArea;
    QWidget *m_chartContainer;
    QGridLayout *m_chartLayout;
    QList<SerialConfig> m_serialConfigs;
    QList<MonitorPointWidget*> m_monitorWidgets;
    //QTabWidget *m_tabWidget;
    HistoryDataWidget *m_historyDataWidget;
    //void setupTabWidget();
    int m_chartCount;
    int m_gridRow;
    int m_gridCol;
    int m_maxCols;
    QString username;
    LogClass *m_pLog;
};
#endif // DATAMONITOR_H
